package com.itheima.service.impl;

import com.itheima.domain.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.UserService;
import com.itheima.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserServiceImpl implements UserService {


    @Override
    public User findById(Integer id) {

        SqlSession sqlSession= MybatisUtils.getSqlSession();
        //获取Mapper的代理对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);

        return mapper.findById(id);
    }

    @Override
    public List<User> findAll() {
        SqlSession sqlSession= MybatisUtils.getSqlSession();
        //获取Mapper的代理对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        return mapper.findAll();
    }

    @Override
    public Integer add(User u) {
        SqlSession sqlSession=MybatisUtils.getSqlSession();
        UserMapper mapper=sqlSession.getMapper(UserMapper.class);
        return mapper.add(u);
    }

    @Override
    public List<User> findByIdOrName(Integer id, String name) {
        SqlSession sqlSession=MybatisUtils.getSqlSession();
        UserMapper mapper=sqlSession.getMapper(UserMapper.class);
        return mapper.findByIdOrName(id,name);
    }

    @Override
    public Integer delete(Integer id) {
        SqlSession sqlSession=MybatisUtils.getSqlSession();
        UserMapper mapper=sqlSession.getMapper(UserMapper.class);
        return mapper.delete(id);
    }



}
